GBML manual / 3D

view3d_shoot

The first instance of obj that a shot from the camera along angle (degrees) reaches within range pixels, before it meets a wall, or nothing. It is what a gun asks.

Game Boy: not available

Game Boy Color: not available

On other consoles this differs: see Side by side and How the consoles differ.

Syntax

view3d_shoot(angle, range, obj) -> ref<object>

Arguments

NameType
anglereal
rangereal
objobject

Returns

ref<object>

Description

The first instance of obj that a shot from the camera along angle (degrees) reaches within range pixels before it meets a wall, or nothing. It is what a gun asks.

The shot is a line from the camera to where the ray meets a wall (or range pixels out, if that is nearer), and it hits the first instance of obj whose collision box the line passes through, counting from the camera. So what a shot can hit is the object's own collision mask, the same boxes every other collision uses: give an enemy a mask as wide as it is drawn. Check the answer with instance_exists before using it.

Example

// fire: hurt the enemy in front of the camera, if a wall does not cover it
var target = view3d_shoot(view3d_angle(), 200, obj_doc_enemy);
if (instance_exists(target)) {
    instance_destroy(target);
}

The first enemy in line of the shot is destroyed; one behind a wall is not.

On the GBA

The shot is a line from the camera to where the ray meets a wall (or range pixels out, if that is nearer), and it hits the first instance of obj whose collision box the line passes through, counting from the camera. So what a shot can hit is the object’s own collision mask, the same boxes every other collision uses: give an enemy a mask that is as wide as it is drawn. Check the answer with instance_exists before using it.

See also: Enemies and items in 3Dview3d_line_clearview3d_raycollision_line